package io.github.junxworks.qt.modules.tushare.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import io.github.junxworks.ep.core.orm.BaseMapper;
import io.github.junxworks.qt.config.ds.Sharding;
import io.github.junxworks.qt.modules.tushare.entity.DStockTradeDailyBasic;

@Sharding
public interface TradeInfoMapper extends BaseMapper {

	@Delete("delete from d_stock_trade_daily where trade_date = #{date}")
	int deleteTradeDataDailyByDate(@Param("date") String date);

	@Delete("delete from d_stock_trade_weekly where trade_date = #{date}")
	int deleteTradeDataWeeklyByDate(@Param("date") String date);

	@Delete("delete from d_stock_trade_monthly where trade_date = #{date}")
	int deleteTradeDataMonthlyByDate(@Param("date") String date);

	@Delete("delete from d_stock_trade_daily_basic where trade_date = #{date}")
	int deleteTradeDataDailyBasicByDate(@Param("date") String date);

	@Delete("delete from d_stock_block_trade where trade_date = #{date}")
	int deleteBlockTradeByDate(@Param("date") String date);

	@Delete("delete from d_stock_trade_cal where cal_date>=#{startDate} and cal_date<=#{endDate}")
	int deleteTradeCal(@Param("startDate") String startDate, @Param("endDate") String endDate);

	@Select("select cal_date from d_stock_trade_cal where is_open=1 order by cal_date asc")
	List<String> selectAllTradeDate();

	@Select("select is_open from d_stock_trade_cal where exchange='SSE' and cal_date=#{date}")
	String queryTradeCalFlagByDate(@Param("date") String date);

	@Select("select pretrade_date from d_stock_trade_cal where exchange='SSE' and cal_date=#{date}")
	String queryPreTradeDateByDate(@Param("date") String date);

	@Delete("delete from d_stock_moneyflow where trade_date = #{date}")
	int deleteTradeDataMoneyFlowByDate(@Param("date") String date);

	@Select("select * from d_stock_trade_daily_basic where ts_code=#{code} and trade_date=#{date}")
	DStockTradeDailyBasic queryTradeDailyBasicByCodeAndDate(@Param("code") String tsCode, @Param("date") String tradeDate);

	@Select("select * from d_stock_trade_daily_basic where trade_date=#{date}")
	List<DStockTradeDailyBasic> queryTradeDailyBasicByDate(@Param("date") String tradeDate);

	@Select("select cal_date from d_stock_trade_cal where is_open=1 and cal_date<=#{targetDate} order by cal_date desc limit 0,1")
	String queryRecentTradeDate(@Param("targetDate") String targetDate);

	@Delete("delete from d_stock_moneyflow_hsgt where trade_date >= #{startDate} and trade_date<=#{endDate}")
	int deleteMoneyFlowHsgt(@Param("startDate") String startDate, @Param("endDate") String endDate);
}
